package cn.edu.bit.ss.util;

import java.util.Vector;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class VectorQueue<T> extends Vector<Object> implements Queue<T> {
	
	private static final long serialVersionUID = 4362280291607915190L;
	
	
	private int size;
	private int volume;
	private static final Log logger = LogFactory.getLog(VectorQueue.class);
	
	
	public VectorQueue(int volume) {
		super();
		this.volume = volume;
	}
	@Override
	public synchronized void add(T object) {
		super.addElement(object);
		size++;
		logger.debug("The current size of the Queue: "+this.size());
	}

	@SuppressWarnings("unchecked")
	@Override
	public synchronized T getNext() {
		if(this.isEmpty()){
			return null;
		}
		T local = (T)super.elementAt(0);
		super.remove(0);
		size--;
		logger.debug("The current size of the Queue: "+this.size());
		return local;
	}
	@Override
	public boolean isEmpty() {
		return super.isEmpty();
	}
	@Override
	public synchronized boolean isFull() {
		return size>=volume;
	}
	public int getSize() {
		return size;
	}
	
	

}
